import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/client/Home/HomeView.vue";
import IndexView from "../views/client/Home/index.vue";
import AboutView from "../views/client/About/AboutView.vue";
import CountView from "../views/client/Count/CountView.vue";
import MessageView from "../views/client/Message/MessageView.vue";
import LoginView from "../views/client/Login/LoginView.vue";
import RegisterView from "../views/client/Login/RegisterView.vue";
import ArticleView from "../views/client/Article/ArticleView.vue";
import SearchView from "../views/client/Article/SearchView.vue";

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/client",
  },
  // 前台路由
  {
    path: "/client",
    name: "client",
    component: HomeView,
    redirect: "client/",
    children: [
      {
        path: "",
        name: "index",
        component: IndexView,
      },
      {
        path: "about",
        name: "about",
        component: AboutView,
      },
      {
        path: "count",
        name: "count",
        component: CountView,
      },
      {
        path: "message",
        name: "message",
        component: MessageView,
      },
      {
        path: "login",
        name: "login",
        component: LoginView,
      },
      {
        path: "register",
        name: "register",
        component: RegisterView,
      },
      {
        path: "article/:id",
        name: "article",
        component: ArticleView,
      },
      {
        path: "search/:keyword",
        name: "search",
        component: SearchView,
      },
    ],
  },
  // 后台路由
  {
    path: "/admin",
    name: "admin",
    component: () => import("../views/admin/Home/Home.vue"),
    redirect: "admin/",
    children: [
      {
        path: "",
        name: "adminIndex",
        component: () => import("../views/admin/Home/index.vue"),
      },
      {
        path: "users",
        name: "adminUsers",
        component: () => import("../views/admin/Users/Users.vue"),
      },
      {
        path: "articleAdd",
        name: "articleAdd",
        component: () => import("../views/admin/Article/Add.vue"),
      },
      {
        path: "articleEdit/:id",
        name: "articleEdit",
        component: () => import("../views/admin/Article/Add.vue"),
      },
      {
        path: "articleList",
        name: "articleList",
        component: () => import("../views/admin/Article/List.vue"),
      },
      {
        path: "articleCategory",
        name: "articleCategory",
        component: () => import("../views/admin/Article/Category.vue"),
      },
      {
        path: "articleComment",
        name: "articleComment",
        component: () => import("../views/admin/Article/Comment.vue"),
      },
      {
        path: "website",
        name: "website",
        component: () => import("../views/admin/WebSite/WebSite.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
